/*
 * MIT License
 *
 * Copyright (c) 2023-present, tangli
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in all
 * copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 */

package tony.test.web.crypto

import com.fasterxml.jackson.databind.BeanProperty
import org.springframework.boot.autoconfigure.SpringBootApplication
import org.springframework.boot.runApplication
import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.Import
import tony.core.annotation.EnableTonyBoot
import tony.core.codec.Encoding
import tony.core.jackson.DeserializeInjectableValueSupplier
import tony.crypto.CryptoHolder
import tony.crypto.SymmetricCryptoHolder
import tony.crypto.symmetric.SymmetricCryptoAlgorithm
import tony.test.web.crypto.req.TestReq2
import tony.web.crypto.autoconfigure.WebCryptoAutoConfiguration

@EnableTonyBoot
@Import(WebCryptoAutoConfiguration::class)
@SpringBootApplication
class TestWebCryptoApp {
    @Bean
    fun cryptoHolder(): CryptoHolder =
        object : SymmetricCryptoHolder {
            override val algorithm: SymmetricCryptoAlgorithm = SymmetricCryptoAlgorithm.DES
            override val secret: String = "xvwe23dvxs"
            override val encoding: Encoding = Encoding.BASE64
        }

    @Bean
    fun inject9() = object : DeserializeInjectableValueSupplier{
        override val name: String = "string"
        override fun value(property: BeanProperty, instance: Any?): String = "hehe"
    }
    @Bean
    fun inject0() = object : DeserializeInjectableValueSupplier{
        override val name: String = "int"
        override fun value(property: BeanProperty, instance: Any?): Int = 1
    }
    @Bean
    fun inject1() = object : DeserializeInjectableValueSupplier{
        override val name: String = "arr"
        override fun value(property: BeanProperty, instance: Any?): Array<Int> = arrayOf(1)
    }
    @Bean
    fun inject2() = object : DeserializeInjectableValueSupplier{
        override val name: String = "list"
        override fun value(property: BeanProperty, instance: Any?): List<Int> = listOf(2)
    }
    @Bean
    fun inject3() = object : DeserializeInjectableValueSupplier{
        override val name: String = "map"
        override fun value(property: BeanProperty, instance: Any?): Map<String,Int> = mapOf()
    }
    @Bean
    fun inject4() = object : DeserializeInjectableValueSupplier{
        override val name: String = "obj"
        override fun value(property: BeanProperty, instance: Any?): TestReq2 = TestReq2()
    }
}

fun main() {
    runApplication<TestWebCryptoApp>()
}
